package com.zdyg.insert.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zdyg.insert.mapper.IdCardMapper;
import com.zdyg.insert.mapper.UserAuthMapper;
import com.zdyg.insert.mapper.UserMapper;
import com.zdyg.insert.pojo.IdCard;
import com.zdyg.insert.pojo.SysUser;
import com.zdyg.insert.pojo.SysUserAuth;
import com.zdyg.insert.service.IIdCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @Author ange
 * @Date2019/12/4 18:05
 * @Version V1.0
 **/
@Service
public class IdCardServiceImpl implements IIdCardService {

    @Autowired
    private IdCardMapper idCardMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserAuthMapper userAuth;
    @Override
    public boolean insert(IdCard idCard) {
        return idCardMapper.insert(idCard)>0;
    }

    @Override
    public Integer insertUser(SysUser sysUser) {
        userMapper.insert(sysUser);
        SysUserAuth sysUserAuth = new SysUserAuth();
        SysUser user = userMapper.selectOne(new QueryWrapper<>(sysUser));
        sysUserAuth.setUser_id(user.getId());
        sysUserAuth.setPhone(sysUser.getPhone());
        System.out.println(sysUser.getNick_name());
        sysUserAuth.setUser_name(sysUser.getNick_name());
        userAuth.insert(sysUserAuth);
        return user.getId();
    }
}